######## 构建 ########
FROM --platform=${BUILDPLATFORM:-amd64} node:12.22.7-alpine3.11

# 安装构建工具
RUN apk add --update --no-cache ca-certificates curl wget cmake build-base git bash python make gcc g++ zlib-dev autoconf automake file nasm \
  && update-ca-certificates

WORKDIR /yapi/vendors

# 拉取 YApi 源码
RUN git clone \
  --single-branch \
  --depth 1 \
  https://github.com/YingHongBin/yapi.git .

RUN mv scripts ../
WORKDIR /yapi/scripts
RUN yarn && yarn build

WORKDIR /yapi/vendors
RUN cp /yapi/scripts/start.js ./start.js
RUN node /yapi/scripts/prepare.js $(pwd)
RUN yarn
RUN node /yapi/scripts/clean.js $(pwd)
RUN mkdir node_modules/ajv-i18n/localize/es
RUN cp ../scripts/es.js node_modules/ajv-i18n/localize/es/

EXPOSE 3000

CMD ["node", "/yapi/vendors/start.js"]
